﻿// <copyright file="CharactersOwner.cs" company="Gravity Age Studios">
// Code released under the MIT license (see License.txt).
// </copyright>
// <author>Vicente Cartas Espinel</author>
// <email>vicente.cartas@gmail.com</email>
namespace LightSwitchApplication
{
    using LightSwitchApplication.UserCode;

    public partial class CharactersOwner
    {
        #region Add/Edit/Delete Character

        partial void gridAddAndEditNew_Execute()
        {
            this.Application.ShowCharacterAddEditOwner(null);
        }

        partial void gridEditSelected_CanExecute(ref bool result)
        {
            result = this.Collection.SelectedItem != null;
        }

        partial void gridEditSelected_Execute()
        {
            this.Application.ShowCharacterAddEditOwner(this.Collection.SelectedItem.Id);
        }

        partial void gridDeleteSelected_CanExecute(ref bool result)
        {
            // Only characters that have not been submitted once can be deleted
            result = this.Collection.SelectedItem != null && 
                     this.Collection.SelectedItem.State == (int)CharacterStateEnum.Created;
        }

        partial void gridDeleteSelected_Execute()
        {
            this.Collection.DeleteSelected();
        }

        #endregion
    }
}
